package com.example.controller.admin;

import com.example.dto.ProfilesAddDTO;
import com.example.entity.HealthProfiles;
import com.example.entity.PageBean;
import com.example.result.Result;
import com.example.service.ProfilesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.annotation.WebServlet;

/**
 * 健康档案
 */
@RestController
@Slf4j
public class ProfilesController {
    @Autowired
    private ProfilesService profilesService;

    /**
     * 分页查询档案
     * @param Page
     * @param PageSize
     * @return
     */
    @GetMapping("/profiles/select")
    public Result select(@RequestParam(defaultValue = "1") Integer Page,
                         @RequestParam(defaultValue = "3") Integer PageSize){
       log.info("查询健康档案:{}");
        PageBean pageBean =  profilesService.select(Page,PageSize);
        return Result.success(pageBean);
    }

    /**
     * 根据id删除数据
     * @param id
     * @return
     */
    @DeleteMapping("/profiles/delete/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据id删除数据:{}",id);
        profilesService.delete(id);
        return Result.success();
    }

    @PutMapping("/profiles/{id}")
    public Result<HealthProfiles> getId(@PathVariable Integer id){
        log.info("根据id查找档案:{}",id);
         HealthProfiles healthProfiles = profilesService.getId(id);
        return Result.success(healthProfiles);

    }

    /**
     * 更新档案
     * @param profilesAddDTO
     * @return
     */
    @PutMapping("/profiles/update")
    public Result update(@RequestBody ProfilesAddDTO profilesAddDTO){
        log.info("更新档案:{}",profilesAddDTO);
        profilesService.update(profilesAddDTO);
        return Result.success();
    }

    @PostMapping("/profiles/add")
    public Result add(@RequestBody ProfilesAddDTO profilesAddDTO){
        log.info("添加档案:{}",profilesAddDTO);
        profilesService.add(profilesAddDTO);
        return Result.success();
    }
}
